Defining the Python Dictionary: Key-Value Mapping
In Python, the Dictionary is a flexible, fundamental data type used for storing data in a descriptive, rather than positional, manner. Unlike sequences like Lists or Tuples, a dictionary is an unordered collection where data is organized using unique names called keys instead of numerical indices. This structure enables incredibly fast data lookup.
1. The Core Structure: Key-Value Pairs
Data is stored as pairs, where a unique Key maps directly to a Value. This design mimics an optimized hash map, ensuring extremely fast retrieval. Keys must be unique and immutable (typically strings or numbers), while Values can be any data type.
{"student_id": 101, "name": "Alex", "grade": 88.5}
2. Dictionary Syntax and Properties
- Dictionaries are defined using curly braces
{}. - The colon
:separates the Key from its corresponding Value (Key:Value). - Dictionaries are mutable, meaning keys and values can be dynamically added, deleted, or modified after creation.
💡 Indexing vs. Key Lookup
Dictionaries do not support numerical indexing (like
[0] or [1]). Data must be retrieved using the specific key name provided during creation (e.g., dictionary["name"]).
TERMINAL
bash — 80x24
> Ready. Click "Run" to execute.
>